import useFileRenameExcelStore from '@renderer/store/Excel/FileRenameExcelStore'

const fileRenameExcelStore = useFileRenameExcelStore()

export default function useExcelImport() {
  // 导入 Excel
  async function handleImportExcel() {
    const excelInitialData = await window.api.importExcel(
      fileRenameExcelStore.getExcelInitialData().path
    )
    if (excelInitialData) {
      fileRenameExcelStore.setExcelInitialData(excelInitialData)
      if (excelInitialData.excelFileContent.length > 0) {
        ElMessage({
          message: '上传成功',
          type: 'success',
          offset: 48
        })
      }
    }
  }

  // 打开文件夹
  function openFolder() {
    const path = fileRenameExcelStore.getExcelInitialData().path
    if (path) {
      window.api.openPath(path)
    }
  }

  return {
    handleImportExcel,
    openFolder
  }
}
